package leetcode.code1172;

import java.util.HashMap;
import java.util.Map;

public class Solution {

	public int maxEqualRowsAfterFlips(int[][] matrix) {
		int m = matrix.length, n = matrix[0].length;
		Map<String, Integer> map = new HashMap<>();
		int ans = 0;
		for (int i = 0; i < m; i++) {
			StringBuffer sb = new StringBuffer();
			if (matrix[i][0] == 1) {
				for (int j = 0; j < n; j++) {
					sb.append(1 - matrix[i][j]);
				}
			} else {
				for (int j = 0; j < n; j++) {
					sb.append(matrix[i][j]);
				}
			}
			String arr = sb.toString();
			map.put(arr, map.getOrDefault(arr, 0) + 1);
			ans = Math.max(ans, map.get(arr));
		}
		return ans;
	}

}
